<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        .box {
            position: relative;
            width: 300px;
            height: 100px;
            border: 1px solid red;
            margin: 0 auto;
        }

        button {
            position: absolute;
            bottom: 20px;
            right: 20px;
            width: 80px;
            height: 30px;
            line-height: 30px;
            text-align: center;
        }

        .countdown {
            position: absolute;
            top: 10px;
            left: 10px;
            width: 30px;
            height: 20px;
            border: 1px solid pink;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="countdown"></div>
        <button>点击跳转</button>
    </div>


    <script>
        // 倒计时模块
        const countdown = document.querySelector('.countdown')
        let i = 5
        // 防止刷新延迟
        function fn() {

            countdown.innerHTML = `${i--}秒`

        }
        fn()
        const n = setInterval(fn, 1000)
        setTimeout(function () {
            location.href = `http://www.itcast.cn`
        }, 5000)
        const button = document.querySelector('button')
        button, addEventListener('click', function () {
            location.href = 'http://www.itcast.cn'
        })

    </script>

</body>

</html>